// 导入请求工具类
import request from '@/utils/request'
import {
    useTokenStore
} from '@/stores/token.js'

// 提供调用仓库列表接口的函数
export const warehouseListService = () => {
    // 在pinia中定义的响应式数据，都不需要.value
    // return request.get('/warehouses',{headers:{'token':tokenStore.token}})
    return request.get('/warehouses')
}


// 提供调用添加仓库接口的函数
export const warehouseAddService = (warehouseData) => {
    const params = new URLSearchParams()
    for (let key in warehouseData) {
        params.append(key, warehouseData[key]);
    }
    return request.post('/warehouse', params)
}

// 仓库修改
export const warehouseUpdateService = (warehouseData) => {
    const requestData = { ...warehouseData }; // 创建一个新对象，复制 warehouseData
    const warehouseID = requestData.warehouseID;
    delete requestData.warehouseID; // 从请求数据中删除 warehouseID

    const params = new URLSearchParams()
    for (let key in requestData) {
        params.append(key, requestData[key]);
    }
    return request.put('/warehouse/'+warehouseID, params)
}

// 仓库删除
export const warehouseDeleteService = (warehouseID) => {
    return request.delete('/warehouse/'+warehouseID)
}
// 仓库搜索
export const warehouseSearchService = (warehouseData) => {
    const requestData = { ...warehouseData }; // 创建一个新对象，复制 warehouseData
    const warehouseID = requestData.warehouseID;

    const params = new URLSearchParams()
    for (let key in requestData) {
        params.append(key, requestData[key]);
    }
    return request.get('/warehouse/'+warehouseID, params)
}